import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/****
 * Run through some tests, and see errors
 */


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Method_Rename_Refactor, renames a method checks for references and renames them too.
 * @author Laurens
 */
public class Method_Rename_Refactor implements RefactoringMethod
{
    /*
     * Initialization and declaration of variables
     */
    String location = " ";
    String oldMethod = " ";
    String newMethod = " ";
    String path = "";
    int r = 0;
    Delete_Method_Refactor delete = new Delete_Method_Refactor();
    referenceFinder find = new referenceFinder();
    FileEditor fileE = new FileEditor();
    characterList characters = new characterList();
    characterEditor characterEditor = new characterEditor();
    replaceValue replace_value = new replaceValue();
    ErrorMessages error = new ErrorMessages();
    /*
     * End of initialization and declaration of variables
     */
    
    /**
     * Constructor does nothing
     */
    public Method_Rename_Refactor()
    {
        //DOES NOTHING
    }

    /**
     * This does the actual renaming of a method refactoring
     * @param parameters
     * @return 
     */
    @Override
    public Vector<String> refactor(Vector<String> parameters)
    {
        /*
         * Creates same look and feel for GUI
         */
        CorrectFile correct = new CorrectFile();
        try 
        {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } 
        catch (Exception ex) 
        {
            Logger.getLogger(Method_Rename_Refactor.class.getName()).log(Level.SEVERE, null, ex);
        } 
        Vector<String> result = new Vector<String>();
        String className = "";
        Vector<String> references = new Vector<String>();
        boolean keywordsNew = false;
        String classN = "";
        if(parameters.isEmpty())
        {
            result.add(error.getErrorMessages("notFound"));
            return result;
        }
        boolean oldMethodFound = false;
        path = parameters.get(0);
        StringTokenizer stClassName = new StringTokenizer(path, "/");
        while(stClassName.hasMoreTokens())
        {
            className = stClassName.nextToken();
        }
        location = path.replace(className, "");
        StringTokenizer st = new StringTokenizer(className, ".");
        classN = st.nextToken();
        Vector<String> methodList = new Vector<String>();
        String file = "";
        String overloadedMethod = "";
        String fileUncorrected = "";
        int counter = 0;
        int cParam = 0;
        Vector<Integer> params = new Vector<Integer>();
        Vector<Integer> lineNumbersOverloaded = new Vector<Integer>();
        try
        {
            /*
             * Reads the file needed to do the rename refactor
             */
            fileUncorrected = fileE.read(path);
            file = correct.returnCorrectFile(fileUncorrected);
            fileE.write(path, file);
        }
        catch(Exception e)
        {

        }
        Database db = new Database();
        boolean duplicate = false;
        int count = 0;
        try
        {
            db.connect();
            db.initializeDB();
            ParserProxy parser = new ParserProxy("FileParser");
            parser.parseString(path);
            methodList = db.getMethod(classN);
            //parameterList = db.getParamater(finalClassName);
        }
        catch(Exception e)
        {
            
        }
        if(parameters.get(1) == null)
        {
            result.add(path);
            Object[] selectionValues2 = new Object[methodList.size()];
            for(int i = 0; i < methodList.size(); i++)
            {
                selectionValues2[i] = methodList.get(i);
            }
            oldMethod = JOptionPane.showInputDialog(null, "Please select the method?", "Method Selection", JOptionPane.QUESTION_MESSAGE, null, selectionValues2,"").toString();
            for(int i = 0; i < methodList.size(); i++)
            {
                if(selectionValues2[i].equals(oldMethod))
                {
                    count++;
                }
            }
            if(count > 1)
            {
                duplicate = true;
            }
            if(duplicate)
            {
                Vector<String> overloaded = overloadedMethod(file, oldMethod);
                Vector<Integer> parameterList = getParameterList(file, oldMethod);
                Object[] selectionOverloaded = new Object[overloaded.size()];
                for(int i = 0; i < overloaded.size(); i++)
                {
                    selectionOverloaded[i] = overloaded.get(i).trim();
                    params.add(parameterList.get(i));
                }
                overloadedMethod = JOptionPane.showInputDialog(null, "A clash has been found, which overloaded method would you like to rename?", "Method Selection", JOptionPane.QUESTION_MESSAGE, null, selectionOverloaded,"").toString();
                cParam = parameters(overloadedMethod);
                lineNumbersOverloaded = getLineNumbersOverloaded(oldMethod, file, cParam);
                references = find.referenceFinderOverloaded(oldMethod, location, classN, cParam);;
                for(int q = 0; q < params.size(); q++)
                {
                    if(cParam == params.get(q))
                    {
                        counter++;
                    }
                }
                if(counter > 1)
                {
                    result.add("Error, not enough information to do the refactoring.");
                    return result;
                }
            }
            newMethod = JOptionPane.showInputDialog("Enter the new method name");
        }
        else
        {
            oldMethod = parameters.get(1);
            newMethod = parameters.get(2);
        }
        keywordsNew = characters.checkKeywords(newMethod);
        boolean punctuation = characters.punctuationCheck(newMethod);
        if(punctuation)
        {
            result.add(error.getErrorMessages("punctuation"));
            return result;
        }
        else if(keywordsNew)
        {
            result.add(error.getErrorMessages("keyword"));
            return result;
        }
        else if(!duplicate)
        {
            boolean methodClash = false;
            try
            {
                //Determines if there is a method clash (Then no refactoring possible)
                //methodClash = checkMatches(newMethod, file);
                methodClash = characterEditor.searchNewValue(newMethod, file);
                //if there is a clash of methods then you will not be able to refactor
                //Ensures that the oldMethod is a method and valid
                oldMethodFound = checkOldMethod(oldMethod, file);
                Scanner scanner = new Scanner(file);
                String superClassName = " ";
                boolean classNameFound = false;
                while(!classNameFound)
                {
                    String currentLine = scanner.nextLine();
                    if(currentLine.contains("public "))
                    {
                        if(currentLine.contains(" class "))
                        {
                            superClassName = getSuperClassName(currentLine);
                        }
                    }
                    else if(" ".equals(superClassName))
                    {

                    }
                    else
                    {
                        classNameFound = true;
                    }
                }
                references = find.referenceFinder(oldMethod, location, classN);
                if(checkReferenceClash(references))
                {
                    result.add("Error, refactoring cancelled because \nthere is a clash in another file using the new method name.\nPlease try a different method name.");
                    return result;
                }
                else if(superClassName.equals(oldMethod))
                {
                    result.add("Error, you may not change the constructor method.\nPlease try a different method name.");
                    return result;
                }
                else if(!oldMethodFound)
                {
                    result.add(error.getErrorMessages("notFound"));
                    return result;
                }
                else if(!methodClash)
                {
                    result.add(replace(lineNumbersMethod(oldMethod, file),oldMethod, newMethod, file));
                }
                else
                {
                    result.add(error.getErrorMessages("alreadyUsed"));
                    return result;
                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
                result.add(error.getErrorMessages("tryFailed"));
                return result;
            }
            for(int o = 0; o < references.size(); o++)
            {
                String fileReferences = "";
                String fileReferences2 = "";
                String sReferences = "";
                String currentPath = references.get(o);
                result.add(currentPath);
                boolean referencesMethodClash = false;
                try
                {
                    FileReader fileReadReference = new FileReader(currentPath);
                    BufferedReader buffer = new BufferedReader(fileReadReference);
                    while((sReferences = buffer.readLine()) != null)
                    {
                            fileReferences2 += sReferences + "\n"; //reads in the right file
                    }
                    fileReferences = correct.returnCorrectFile(fileReferences2);
                    referencesMethodClash = characterEditor.searchNewValue(newMethod, fileReferences);
                    if(referencesMethodClash)
                    {
                        //result.add();
                    }
                }
                catch(Exception e)
                {

                }
                try 
                {   
                    result.add(replace(lineNumbersMethodReferences(oldMethod, fileReferences),oldMethod, newMethod, fileReferences));
                } 
                catch (Exception ex) 
                {
                    Logger.getLogger(Method_Rename_Refactor.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }    
        else
        {
            int lineNumbers = 0;
            int length = 1;
            Scanner scanner = new Scanner(file);
            int i = 1;
            while(scanner.hasNext())
            {
                String currentLine = scanner.nextLine();
                if(currentLine.contains("public "))
                {
                    for(int p = 0; p < 17; p++)
                    {
                        if(currentLine.contains(overloadedMethod))
                        {
                            lineNumbers = i;
                        }
                    }
                }
                else if(currentLine.contains("private "))
                {
                    for(int p = 0; p < 17; p++)
                    {
                        if(currentLine.contains(overloadedMethod))
                        {
                            lineNumbers = i;
                        }
                    }
                }
                i++;
            }
            if(lineNumbersOverloaded.size() > 0)
            {
                result.add(replace(lineNumbers, file, oldMethod, cParam));
            }
            else
            {
                result.add(replace(lineNumbers, file, oldMethod, cParam));
            }
            for(int o = 0; o < references.size(); o++)
            {
                String fileReferences = "";
                String fileReferences2 = "";
                String sReferences = "";
                String currentPath = references.get(o);
                result.add(currentPath);
                boolean referencesMethodClash = false;
                try
                {
                    FileReader fileReadReference = new FileReader(currentPath);
                    BufferedReader buffer = new BufferedReader(fileReadReference);
                    while((sReferences = buffer.readLine()) != null)
                    {
                            fileReferences2 += sReferences + "\n"; //reads in the right file
                    }
                    fileReferences = correct.returnCorrectFile(fileReferences2);
                    referencesMethodClash = characterEditor.searchNewValue(newMethod, fileReferences);
                    if(referencesMethodClash)
                    {
                        //result.add();
                    }
                }
                catch(Exception e)
                {

                }
                try 
                {   
                    result.add(replace(lineNumbersMethodReferencesOverload(oldMethod, fileReferences, cParam),oldMethod, newMethod, fileReferences));
                } 
                catch (Exception ex) 
                {
                    Logger.getLogger(Method_Rename_Refactor.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return result;
    }

    /**
     * Determines the various line numbers where oldMethod is found
     * @param lineNumbers
     * @param oldMethod
     * @param file
     * @return
     */
    public Vector<Integer> lineNumbersMethod(String oldMethod, String file)
    {
        int i = 1;
        Vector<String> characterList = characters.characterListMethod();
        Vector<Integer> result = new Vector<Integer>();
        Scanner scanner = new Scanner(file);
        Vector<String> spaces = new Vector<String>();
        spaces.add("");
        spaces.add(" ");
        spaces.add("  ");
        spaces.add("   ");
        spaces.add("    ");
        spaces.add("     ");
        spaces.add("      ");
        spaces.add("       ");
        spaces.add("        ");
        spaces.add("         ");
        spaces.add("          ");
        //Scans the file to determine the line numbers of occurences of oldMethod
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            for(int l = 0; l < characterList.size(); l++)
            {
                for(int q = 0; q < spaces.size(); q++)
                {
                    //Checks if the method is found with certain characters before and after oldMethod
                    if(currentLine.contains(characterList.get(l) + oldMethod + spaces.get(q)+"("))
                    {
                        result.add(i);
                        l = characterList.size();
                        q = spaces.size();
                    }
                    else
                    {
                        //NOTHING
                    }
                }
            }
            i++;
        }
        //returns the unsorted line numbers of occurences of oldMethod
        return result;
    }

    /**
     * Determines the various line numbers where oldMethod is found
     * @param lineNumbers
     * @param oldMethod
     * @param file
     * @return
     */
    public Vector<Integer> lineNumbersMethodReferences(String oldMethod, String file)
    {
        int i = 1;
        int z = r;
        Vector<Integer> result = new Vector<Integer>();
        Scanner scanner = new Scanner(file);
        //Scans the file to determine the line numbers of occurences of oldMethod
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            if(find.variable.get(0) == null)
            {
                return null;
            }
            else
            {
                if(z == 0)
                {
                    if(currentLine.contains(find.variable.get(z) +"."+oldMethod+"("))
                    {
                        result.add(i);
                        r++;
                    }
                }
                for(int u = 0; u < find.variable.size(); u++)
                {
                    if(currentLine.contains(find.variable.get(u) +"."+oldMethod+"("))
                    {
                        result.add(i);
                        r++;
                    }
                }
            }
            i++;
        }
        //returns the unsorted line numbers of occurences of oldMethod
        return result;
    }

    /**
     * Checks that oldMethod is allowed to be changed
     * @param oldMethod
     * @param file
     * @return 
     */
    private boolean checkOldMethod(String oldMethod, String file) 
    {
        Scanner scanner = new Scanner(file);
        boolean found = false;
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            if(currentLine.contains(" "+oldMethod+" "))
            {
                if(currentLine.contains("class "))
                {
                    found = false;
                    return found;
                }
                else if(currentLine.contains("public "))
                {
                    found = true;
                    return found;
                }
                else if(currentLine.contains("private "))
                {
                    found = true;
                    return found;
                }
                else
                {
                    found = false;
                }
            }
            else if(currentLine.contains(oldMethod+"("))
            {
                if(currentLine.contains("class "))
                {
                    found = false;
                    //return found;
                }
                else if(currentLine.contains("public "))
                {
                    found = true;
                    return found;
                }
                else if(currentLine.contains("private "))
                {
                    found = true;
                    return found;
                }
                else
                {
                    found = false;
                }
            }
            else if(currentLine.contains(oldMethod+" ("))
            {
                if(currentLine.contains("class "))
                {
                    found = false;
                    //return found;
                }
                else if(currentLine.contains("public "))
                {
                    found = true;
                    return found;
                }
                else if(currentLine.contains("private "))
                {
                    found = true;
                    return found;
                }
                else
                {
                    found = false;
                }
            }
            else
            {
                found = false;
            }
        }
        return found;
    }
    
    /**
     * Gets the name of the superclass
     * @param currentLine
     * @return 
     */
    public String getSuperClassName(String currentLine)
    {
        StringTokenizer st = new StringTokenizer(currentLine, " ");
        String result = " ";
        while(st.hasMoreTokens())
        {
            if(" ".equals(result))
            {
                String current = st.nextToken();
                if("public".equals(current))
                {
                    
                }
                else if("class".equals(current))
                {
                    
                }
                else if("abstract".equals(current))
                {
                    
                }    
                else
                {
                    result = current;
                }
            }
            else
            {
                st.nextToken();
            }
        }
        return result;
    }
    
    /** 
     * Ensures that no reference methods use the same name as newMethod
     * @param references
     * @return 
     */
    public boolean checkReferenceClash(Vector<String> references)
    {
        boolean clash = false;
        for(int o = 0; o < references.size(); o++)
        {
            String currentPath = references.get(o);
            String fileReferences = " ";
            String sReferences = " ";
            boolean referencesMethodClash = false;
            if(references.get(o) == null ? path == null : references.get(o).equals(path))
            {
                clash = false;
            }
            else
            {
                try
                {
                    FileReader fileReadReference = new FileReader(currentPath);
                    BufferedReader buffer = new BufferedReader(fileReadReference);
                    while((sReferences = buffer.readLine()) != null)
                    {
                            fileReferences += sReferences + "\n"; //reads in the right file
                    }
                    referencesMethodClash = characterEditor.searchNewValue(newMethod, fileReferences);
                    if(referencesMethodClash)
                    {
                        clash = true;
                        return clash;
                    }
                }
                catch(Exception e)
                {

                }
            }
        }
        return clash;
    }

    /**
     * Returns a description of the current refactoring method
     * @return 
     */
    @Override
    public String description() 
    {
        return "Renames the method inside the current class, aswell as any reference to this method in other classes.";
    }

    private String replace(Vector<Integer> lineNumbers, String oldMethod, String newMethod, String file) 
    {
        Scanner scanner = new Scanner(file);
        Vector<Integer> sortedLineNumbers = new Vector<Integer>();
        if(lineNumbers == null)
        {
            return null;
        }
        //Sorting the lineNumbers in desceding order
        int i = 1;
        int lineCounter = 0;
        sortedLineNumbers = characterEditor.insertion_sort(lineNumbers);
        Vector<String> alphabet = characters.alphabet();
        Vector<Integer> finalSortedLineNumbers = new Vector<Integer>();
        finalSortedLineNumbers = characterEditor.removeDuplicates(sortedLineNumbers);
        Vector<String> result = new Vector<String>();
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            if(i == finalSortedLineNumbers.get(lineCounter))
            {
                boolean letterFound = false;
//                if(currentLine.contains("\""))
//                {
//                    result.add(dealWithQuotes(currentLine, oldValue, newValue));
//                }
                for(int y = 0; y < alphabet.size(); y++)
                {
                    //Checks to make sure there is no numbers letter before the oldValue
                    if(currentLine.contains("."+oldMethod))
                    {
                        if(currentLine.contains(oldMethod + alphabet.get(y)))
                        {
                            result.add(replace_value.dealWithExtras(currentLine, oldMethod, newMethod));
                            letterFound = true;
                            y = alphabet.size() + 1;
                        }
                        else if(currentLine.contains(alphabet.get(y) + oldMethod))
                        {
                            result.add(replace_value.dealWithExtras(currentLine, oldMethod, newMethod));
                            letterFound = true;
                            y = alphabet.size() + 1;
                        }
                        else
                        {
                            //letterFound = false;
                            //y = alphabet.size() + 1;
                        }
                    }
                }
                //If no numbers is found then you may replace the parameter
                if(letterFound == false)
                {
                    if(currentLine.contains("."+ oldMethod))
                    {
                        result.add(currentLine.replace("."+oldMethod, "."+newMethod));
                    }
                    else if(currentLine.contains(" "+oldMethod+"("))
                    {
                        result.add(currentLine.replace(" "+oldMethod+"(", " "+newMethod+"("));
                    }
                    else if(currentLine.contains(" "+oldMethod+" ("))
                    {
                        result.add(currentLine.replace(" "+oldMethod+" (", " "+newMethod+" ("));
                    }
                }
                else
                {
                    
                }
                if(lineCounter < finalSortedLineNumbers.size())
                {
                    if (lineCounter == finalSortedLineNumbers.size() - 1)
                    {

                    }
                    else
                    {
                        lineCounter++;
                    }
                }
            }
            else
            {
                result.add(currentLine);
            }
            i++;
        }
        String output = "";
        for(int u = 0; u < result.size(); u++)
        {
            output += result.get(u) + "\n";
        }
        return output;
    }
    
    private Vector<Integer> getParameterList(String file, String oldMethod) 
    {
        Vector<Integer> result = new Vector<Integer>();
        Scanner scanner = new Scanner(file);
        Vector<String> spaces = new Vector<String>();
        spaces.add("");
        spaces.add(" ");
        spaces.add("  ");
        spaces.add("   ");
        spaces.add("    ");
        spaces.add("     ");
        spaces.add("      ");
        spaces.add("       ");
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            if(currentLine.contains("public"))
            {
                for(int u = 0;  u < spaces.size(); u++)
                {
                    if(currentLine.contains(" "+oldMethod+spaces.get(u)+"(") )
                    {
                        result.add(parameters(currentLine));                        
                    }
                }
            }
            else if(currentLine.contains("private"))
            {
                for(int u = 0;  u < spaces.size(); u++)
                {
                    if(currentLine.contains(" "+oldMethod+spaces.get(u)+"(") )
                    {
                        result.add(parameters(currentLine));                        
                    }
                }
            }
            else
            {
                
            }
        }
        return result;
    }
    
    public Vector<String> overloadedMethod(String file, String oldMethod)
    {
        Vector<String> result = new Vector<String>();
        Scanner scanner = new Scanner(file);
        Vector<String> spaces = new Vector<String>();
        spaces.add("");
        spaces.add(" ");
        spaces.add("  ");
        spaces.add("   ");
        spaces.add("    ");
        spaces.add("     ");
        spaces.add("      ");
        spaces.add("       ");
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            if(currentLine.contains("public"))
            {
                for(int u = 0;  u < spaces.size(); u++)
                {
                    if(currentLine.contains(" "+oldMethod+spaces.get(u)+"(") )
                    {
                        result.add(currentLine);                        
                    }
                }
            }
            else if(currentLine.contains("private"))
            {
                for(int u = 0;  u < spaces.size(); u++)
                {
                    if(currentLine.contains(" "+oldMethod+spaces.get(u)+"(") )
                    {
                        result.add(currentLine);                        
                    }
                }
            }
            else
            {
                
            }
        }
        return result;
    }
    
    private int parameters(String currentLine) 
    {
        int output = 0;
        StringTokenizer st = new StringTokenizer(currentLine, "(");
        st.nextToken();
        String current = "";
        while(st.hasMoreTokens())
        {
            current += st.nextToken();
        }
        String noBrackets = current.trim().substring(0, current.length() - 1);
        if(currentLine.contains("()"))
        {
            return 0;
        }
        else if(currentLine.contains("( )"))
        {
            
        }
        else
        {
            output++;
        }
        StringTokenizer st2 = new StringTokenizer(noBrackets);
        while(st2.hasMoreTokens())
        {
            String current2 = st2.nextToken();
            if(current2.contains(","))
            {
                output++;
            }
        }
        return output;
    }
    
    private Vector<Integer> getLineNumbersOverloaded(String oldMethod, String file, int paramNum) 
    {
        Scanner scanner = new Scanner(file);
        Vector<Integer> result = new Vector<Integer>();
        int i = 1;
        Vector<String> spaces = new Vector<String>();
        spaces.add("");
        spaces.add(" ");
        spaces.add("  ");
        spaces.add("   ");
        spaces.add("    ");
        spaces.add("     ");
        spaces.add("      ");
        spaces.add("       ");
        spaces.add("        ");
        spaces.add("         ");
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            if(!currentLine.contains("public "))
            {
                for(int u = 0; u < spaces.size(); u++)
                {
                    if(currentLine.contains(" "+oldMethod+spaces.get(u)+"("))
                    {
                        if(parameters(currentLine) == paramNum)
                        {
                            result.add(i);
                        }
                    }
                }
            }
            i++;
        }
        return result;
    }

    private String replace(int lineNumbers, String file, String oldMethod, int cParam)
    {
        Vector<String> spaces = new Vector<String>();
        Scanner scanner = new Scanner(file);
        Vector<String> result = new Vector<String>();
        int i = 1;
        spaces.add("");
        spaces.add(" ");
        spaces.add("  ");
        spaces.add("   ");
        spaces.add("    ");
        spaces.add("     ");
        spaces.add("      ");
        spaces.add("       ");
        spaces.add("        ");
        spaces.add("         ");
        boolean oneParameterError = false;
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            if(i == lineNumbers)
            {
                result.add(currentLine.replace(" "+oldMethod, " "+newMethod));
            }
            else if(currentLine.contains(" "+oldMethod))
            {
                if(parameters(currentLine) == cParam)
                {
                    if(currentLine.contains("."+oldMethod))
                    {
                        result.add(currentLine.replace("."+oldMethod, "."+newMethod));
                    }
                    else 
                    {
                        for(int u = 0; u < spaces.size(); u++)
                        {
                            if(currentLine.contains(" "+oldMethod+spaces.get(u)+"("))
                            {
                                result.add(currentLine.replace(" "+oldMethod, " "+newMethod));
                                oneParameterError = true;
                                u = spaces.size();
                            }
                            else
                            {
                                oneParameterError = false;
                            }
                        }
                        if(!oneParameterError)
                        {
                            result.add(currentLine);
                        }
                    }
                }
                else
                {
                    result.add(currentLine);
                }
            }
            else
            {
                result.add(currentLine);
            }
            i++;
        }
        String output = "";
        for(int y = 0; y < result.size(); y++)
        {
            output += result.get(y) + "\n";
        }
        return output;
    }
    
    /**
     * Determines the various line numbers where oldMethod is found
     * @param lineNumbers
     * @param oldMethod
     * @param file
     * @return
     */
    public Vector<Integer> lineNumbersMethodReferencesOverload(String oldMethod, String file, int cParam)
    {
        int i = 1;
        int z = r;
        Vector<Integer> result = new Vector<Integer>();
        Scanner scanner = new Scanner(file);
        //Scans the file to determine the line numbers of occurences of oldMethod
        while(scanner.hasNext())
        {
            String currentLine = scanner.nextLine();
            if(find.variable.get(0) == null)
            {
                return null;
            }
            else
            {
                if(z == 0)
                {
                    if(currentLine.contains(find.variable.get(z) +"."+oldMethod+"("))
                    {
                        if(parameters(currentLine) == cParam)
                        {
                            result.add(i);
                            r++;
                        }
                    }
                }
                for(int u = 0; u < find.variable.size(); u++)
                {
                    if(currentLine.contains(find.variable.get(u) +"."+oldMethod+"("))
                    {
                        if(parameters(currentLine) == cParam)
                        {
                            result.add(i);
                            r++;
                        }
                    }
                }
            }
            i++;
        }
        //returns the unsorted line numbers of occurences of oldMethod
        return result;
    }
}

